﻿<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:msds="http://matsadaml.org/msds/v1.0"
	xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/1999/xhtml"
	xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:exsl="http://exslt.org/common"
	extension-element-prefixes="exsl msxsl" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	exclude-result-prefixes="exsl msxsl xsl xs msds">
	<xsl:output method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
		doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
		encoding="UTF-8" indent="yes" />
	<xsl:strip-space elements="*" />
	<xsl:param name="CompanyDB"
		select="document('../../ResourceFiles/CompanyDB.xml')/msds:companyDB" />
	<xsl:param name="Company"
		select="$CompanyDB/msds:company[@key = current()/msds:product/msds:company/@key]" />
	<xsl:param name="Language"
		select="$Company/msds:custom-items/msds:item[@name = 'default-language']" />
	<xsl:param name="Country"
		select="$Company/msds:custom-items/msds:item[@name = 'default-country']" />
	<xsl:param name="SubstDBs">
		<xsl:variable name="DBs"
			select="document('../../Substances/SubstanceDBs.xml')/msds:substanceDBs" />
		<xsl:for-each select="$DBs/msds:db">
			<msds:substanceDB key="{@key}">
				<xsl:copy-of select="document(msds:location)/msds:substanceDB/*" />
			</msds:substanceDB>
		</xsl:for-each>
	</xsl:param>
	<msxsl:script language="JScript" implements-prefix="exsl">
		this['node-set'] = function (x) {
		return x;
		}
    </msxsl:script>
	<xsl:variable name="SubstanceDBs" select="exsl:node-set($SubstDBs)" />
	<!--
		<xsl:stylesheet version="1.0"
		xmlns:msds="http://matsadaml.org/msds/v1.0"
		xmlns:xs="http://www.w3.org/2001/XMLSchema"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
		xmlns:msxsl="urn:schemas-microsoft-com:xslt"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:param
		name="SubstanceDBs" select="exsl:node-set($SubstDBs)"/> <xsl:choose>
		<xsl:when test="function-available('exsl:node-set')"> <xsl:value-of
		select="exsl:node-set($SubstDBs)"/> </xsl:when> <xsl:otherwise>
		<xsl:value-of select="msxsl:node-set($SubstDBs)"/> </xsl:otherwise>
		</xsl:choose>
	-->
	<xsl:param name="RiskPhrases"
		select="document('../../ResourceFiles/RiskPhrases.xml')/msds:riskPhrases" />
	<xsl:param name="SafetyPhrases"
		select="document('../../ResourceFiles/SafetyPhrases.xml')/msds:safetyPhrases" />
	<xsl:param name="Hazards"
		select="document('../../ResourceFiles/Hazards.xml')/msds:hazards" />
	<xsl:param name="ExposureLimitRemarks"
		select="document('../../ResourceFiles/ExposureLimitRemarks.xml')/msds:exposureLimitRemarks" />
	<xsl:param name="Standard_TextTags" select="document('Standard_TextTags.xml')/textTags" />
	<xsl:variable name="DecimalFormat"
		select="$Standard_TextTags/textTag[@key = 'DecimalFormat']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
	<xsl:decimal-format name="AngloSaxon"
		decimal-separator="." grouping-separator="," percent="%" minus-sign="-" />
	<xsl:decimal-format name="WestEuropean"
		decimal-separator="," grouping-separator="." percent="%" minus-sign="-" />
	<xsl:decimal-format name="NorthEuropean"
		decimal-separator="," grouping-separator=" " percent="%" minus-sign="-" />
	<!--  -->
	<!--Root tag-->
	<!--  -->
	<xsl:template match="/">
		<xsl:apply-templates />
	</xsl:template>
	<!--  -->
	<!--product tag, start doing stuff-->
	<!--  -->
	<xsl:template match="msds:product">
		<html lang="en" xml:lang="en">
			<head>
				<title>
					<xsl:value-of
						select="$Standard_TextTags/textTag[@key = 'MaterialSafetyDataSheet']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
					<xsl:text>: </xsl:text>
					<xsl:value-of select="$Company/msds:contactDetails/msds:companyName" />
				</title>
				<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
				<meta http-equiv="Content-Language" content="{$Language}" />
				<!--
					<style type="text/css" media="screen"> @import "<xsl:value-of
					select="$Company/msds:custom-items/msds:item[@name =
					'css-screen']"/> ";</style>
				-->
				<link rel="stylesheet" type="text/css" media="screen"
					href="{$Company/msds:custom-items/msds:item[@name = 'css-screen']}" />
				<link rel="stylesheet" type="text/css" media="print"
					href="{$Company/msds:custom-items/msds:item[@name = 'css-print']}" />
				<meta name="MSSmartTagsPreventParsing" content="true" />
			</head>
			<body>
				<div id="page">
					<div id="header">
						<h3>
							<xsl:value-of
								select="$Standard_TextTags/textTag[@key = 'MaterialSafetyDataSheet']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
						</h3>
						<h1>
							<xsl:value-of select="$Company/msds:contactDetails/msds:companyName" />
						</h1>
					</div>
					<div id="content">
						<xsl:call-template name="IntroductionSection" />
						<xsl:apply-templates select="msds:hazardsIdentification" />
						<xsl:call-template name="CompositionSection" />
						<xsl:apply-templates select="msds:firstAidMeasures" />
						<xsl:apply-templates select="msds:fireFightingMeasures" />
						<xsl:apply-templates select="msds:accidentalReleaseMeasures" />
						<xsl:apply-templates select="msds:handlingAndStorage" />
						<xsl:apply-templates select="msds:personalProtection" />
						<xsl:apply-templates select="msds:properties" />
						<xsl:apply-templates select="msds:stability" />
						<xsl:apply-templates select="msds:toxicology" />
						<xsl:apply-templates select="msds:ecotoxicology" />
						<xsl:apply-templates select="msds:disposal" />
						<xsl:apply-templates select="msds:transportation" />
						<xsl:apply-templates select="msds:regulatoryInformation" />
						<xsl:apply-templates select="msds:otherInformation" />
					</div>
					<div id="footer">
						<p>
							<span lang="sv" class="vänster">
								<xsl:value-of
									select="$Standard_TextTags/textTag[@key = 'MSDSpublishedBy']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
								<xsl:text>: </xsl:text>
								<xsl:value-of select="$Company/msds:contactDetails/msds:companyName" />
							</span>
							<span class="mitten">
								<xsl:value-of
									select="$Standard_TextTags/textTag[@key = 'Product']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
								<xsl:text>: </xsl:text>
								<xsl:value-of
									select="//msds:name[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
							</span>
							<span class="höger" />
						</p>
					</div>
				</div>
			</body>
		</html>
	</xsl:template>
	<!--  -->
	<!--product tag, create Introduction section-->
	<!--  -->
	<xsl:template name="IntroductionSection">
		<div class="section" id="IntroductionSection">
			<h2>
				<xsl:value-of
					select="$Standard_TextTags/textTag[@key = 'IntroductionTitle']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
			</h2>
			<table>
				<tbody>
					<tr>
						<td>
							<b>
								<xsl:value-of
									select="$Standard_TextTags/textTag[@key = 'ProductName']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
							</b>
						</td>
						<td>
							<xsl:value-of
								select="msds:name[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
						</td>
					</tr>
					<tr>
						<td>
							<b>
								<xsl:value-of
									select="$Standard_TextTags/textTag[@key = 'Supplier']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
							</b>
						</td>
						<td>
							<xsl:value-of select="$Company/msds:contactDetails/msds:companyName" />
						</td>
					</tr>
					<tr>
						<td>
							<b>
								<xsl:value-of
									select="$Standard_TextTags/textTag[@key = 'Address']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
							</b>
						</td>
						<td>
							<xsl:value-of select="$Company/msds:contactDetails/msds:address1" />
							,
							<xsl:if test="$Company/msds:contactDetails/msds:address2">
								<xsl:value-of select="$Company/msds:contactDetails/msds:address2" />
								,
							</xsl:if>
							<xsl:if test="$Company/msds:contactDetails/msds:address3">
								<xsl:value-of select="$Company/msds:contactDetails/msds:address3" />
								,
							</xsl:if>
							<xsl:value-of select="$Company/msds:contactDetails/msds:postCode" />
							,
							<xsl:value-of select="$Company/msds:contactDetails/msds:city" />
							,
							<xsl:value-of select="$Company/msds:contactDetails/msds:country" />
						</td>
					</tr>
					<tr>
						<td>
							<b>
								<xsl:value-of
									select="$Standard_TextTags/textTag[@key = 'Telephone']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
							</b>
						</td>
						<td>
							<xsl:value-of select="$Company/msds:contactDetails/msds:telephone" />
						</td>
					</tr>
				</tbody>
			</table>
			<xsl:variable name="paragraphs"
				select="msds:information/msds:paragraph[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
			<xsl:if test="$paragraphs">
				<p />
				<xsl:call-template name="CreateParagraphTable">
					<xsl:with-param name="Paragraphs" select="$paragraphs" />
				</xsl:call-template>
			</xsl:if>
		</div>
	</xsl:template>
	<!--  -->
	<!-- create section for hazards -->
	<!--  -->
	<xsl:template match="msds:hazardsIdentification">
		<div class="section" id="HazardsSection">
			<h2>
				<xsl:value-of
					select="$Standard_TextTags/textTag[@key = 'HazardsTitle']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
			</h2>
			<xsl:if
				test="//msds:regulatoryInformation/msds:hazardSymbols/msds:hazardSymbol">
				<xsl:apply-templates
					select="//msds:regulatoryInformation/msds:hazardSymbols" />
			</xsl:if>
			<xsl:variable name="paragraphs"
				select="msds:paragraph[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
			<xsl:if test="$paragraphs">
				<p />
				<xsl:call-template name="CreateParagraphTable">
					<xsl:with-param name="Paragraphs" select="$paragraphs" />
				</xsl:call-template>
			</xsl:if>
		</div>
	</xsl:template>
	<!--  -->
	<!-- create section for composition-->
	<!--  -->
	<xsl:template name="CompositionSection">
		<div class="section" id="CompositionSection">
			<h2>
				<xsl:value-of
					select="$Standard_TextTags/textTag[@key = 'CompositionTitle']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
			</h2>
			<xsl:if test="msds:substances/msds:substance">
				<table class="outlined">
					<tbody>
						<tr>
							<xsl:for-each
								select="$Standard_TextTags/textTag[@key = 'CompositionTableHeader']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]/textTag">
								<td>
									<b>
										<xsl:value-of select="." />
									</b>
								</td>
							</xsl:for-each>
						</tr>
						<xsl:for-each select="msds:substances/msds:substance">
							<tr>
								<td>
									<xsl:value-of
										select="$SubstanceDBs/msds:substanceDB[@key = current()/@db]/msds:substance-entry[@id=current()/@id]/msds:names/msds:name[@lang = $Language]" />
								</td>
								<td>
									<xsl:value-of
										select="$SubstanceDBs/msds:substanceDB[@key = current()/@db]/msds:substance-entry[@id=current()/@id]/msds:cas-number" />
								</td>
								<td>
									<xsl:value-of
										select="$SubstanceDBs/msds:substanceDB[@key = current()/@db]/msds:substance-entry[@id=current()/@id]/msds:eg-number" />
								</td>
								<td>
									<xsl:for-each
										select="$Hazards/msds:hazard[$SubstanceDBs/msds:substanceDB[@key = current()/@db]/msds:substance-entry[@id=current()/@id]/msds:hazardCodes/msds:hazardCode/@key=@key]">
										<xsl:sort select="msds:code" />
										<xsl:value-of select="msds:code" />
										<xsl:if test="not(position()=last())">
											<xsl:text>, </xsl:text>
										</xsl:if>
									</xsl:for-each>
								</td>
								<td>
									<xsl:for-each
										select="$SubstanceDBs/msds:substanceDB[@key = current()/@db]/msds:substance-entry[@id=current()/@id]/msds:riskPhrases/msds:riskPhrase">
										<xsl:sort
											select="$RiskPhrases/msds:riskPhrase[@key=current()/@key]/msds:code" />
										<xsl:value-of
											select="$RiskPhrases/msds:riskPhrase[@key=current()/@key]/msds:code" />
										<xsl:if test="not(position()=last())">
											<xsl:text>, </xsl:text>
										</xsl:if>
									</xsl:for-each>
								</td>
								<td>
									<xsl:call-template name="FormatNumber">
										<xsl:with-param name="Value"
											select="msds:concentration/msds:min" />
										<xsl:with-param name="FormatString"
											select="$Standard_TextTags/textTag[@key = 'FormatString_0']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
									</xsl:call-template>
									<xsl:value-of select="' '" />
									<xsl:value-of select="msds:concentration/msds:min/@unit" />
								</td>
								<td>
									<xsl:call-template name="FormatNumber">
										<xsl:with-param name="Value"
											select="msds:concentration/msds:max" />
										<xsl:with-param name="FormatString"
											select="$Standard_TextTags/textTag[@key = 'FormatString_0']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
									</xsl:call-template>
									<xsl:value-of select="' '" />
									<xsl:value-of select="msds:concentration/msds:max/@unit" />
								</td>
							</tr>
						</xsl:for-each>
					</tbody>
				</table>
				<p>
					<b>
						<xsl:value-of
							select="$Standard_TextTags/textTag[@key = 'CompositionRefComment']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
					</b>
				</p>
				<p>
					<b>
						<xsl:value-of
							select="$Standard_TextTags/textTag[@key = 'HazardousCodesExplanation']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
						<xsl:text> </xsl:text>
					</b>
					<xsl:variable name="unique-hazardCode"
						select="$Hazards/msds:hazard[$SubstanceDBs/msds:substanceDB[@key = current()/msds:substances/msds:substance/@db]/msds:substance-entry[@id=current()/msds:substances/msds:substance/@id]/msds:hazardCodes/msds:hazardCode/@key=@key]" />
					<xsl:for-each select="$unique-hazardCode">
						<xsl:sort select="msds:code" />
						<xsl:value-of select="msds:code" />
						<xsl:text>=</xsl:text>
						<xsl:value-of
							select="msds:text[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
						<xsl:if test="not(position()=last())">
							<xsl:text>, </xsl:text>
						</xsl:if>
					</xsl:for-each>
				</p>
			</xsl:if>
			<xsl:variable name="paragraphs"
				select="msds:comment/msds:paragraph[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
			<xsl:if test="$paragraphs">
				<p />
				<div id="section">
					<xsl:call-template name="CreateParagraphTable">
						<xsl:with-param name="Paragraphs" select="$paragraphs" />
					</xsl:call-template>
				</div>
			</xsl:if>
		</div>
	</xsl:template>
	<!--  -->
	<!--
		tags with paragraphs or steps, create section headers and table
		beneath. Except personalProtection tag
	-->
	<!--  -->
	<xsl:template
		match="msds:firstAidMeasures | msds:fireFightingMeasures | msds:accidentalReleaseMeasures | msds:handlingAndStorage | msds:properties | msds:stability | msds:toxicology | msds:ecotoxicology | msds:disposal | msds:transportation">
		<xsl:variable name="paragraphs"
			select="msds:paragraph[contains(@countries, concat($Country, '; ')) and @lang = $Language] | msds:step[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
		<div class="section" id="StandardSection">
			<h2>
				<xsl:choose>
					<xsl:when test="local-name(.) = 'firstAidMeasures'">
						<xsl:value-of
							select="$Standard_TextTags/textTag[@key = 'FirstAidTitle']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
					</xsl:when>
					<xsl:when test="local-name() = 'fireFightingMeasures'">
						<xsl:value-of
							select="$Standard_TextTags/textTag[@key = 'FireFightingTitle']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
					</xsl:when>
					<xsl:when test="local-name() = 'accidentalReleaseMeasures'">
						<xsl:value-of
							select="$Standard_TextTags/textTag[@key = 'AccidentalReleaseTitle']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
					</xsl:when>
					<xsl:when test="local-name() = 'handlingAndStorage'">
						<xsl:value-of
							select="$Standard_TextTags/textTag[@key = 'HandlingStorageTitle']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
					</xsl:when>
					<xsl:when test="local-name() = 'properties'">
						<xsl:value-of
							select="$Standard_TextTags/textTag[@key = 'PropertiesTitle']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
					</xsl:when>
					<xsl:when test="local-name() = 'stability'">
						<xsl:value-of
							select="$Standard_TextTags/textTag[@key = 'StabilityTitle']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
					</xsl:when>
					<xsl:when test="local-name() = 'toxicology'">
						<xsl:value-of
							select="$Standard_TextTags/textTag[@key = 'ToxicologicalTitle']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
					</xsl:when>
					<xsl:when test="local-name() = 'ecotoxicology'">
						<xsl:value-of
							select="$Standard_TextTags/textTag[@key = 'EcologicalTitle']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
					</xsl:when>
					<xsl:when test="local-name() = 'disposal'">
						<xsl:value-of
							select="$Standard_TextTags/textTag[@key = 'DisposalTitle']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
					</xsl:when>
					<xsl:when test="local-name() = 'transportation'">
						<xsl:value-of
							select="$Standard_TextTags/textTag[@key = 'TransportTitle']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
					</xsl:when>
				</xsl:choose>
			</h2>
			<xsl:call-template name="CreateParagraphTable">
				<xsl:with-param name="Paragraphs" select="$paragraphs" />
			</xsl:call-template>
		</div>
	</xsl:template>
	<!--  -->
	<!--
		personalProtection tag, note here will also be a table based on the
		substances tag
	-->
	<!--  -->
	<xsl:template match="msds:personalProtection">
		<div class="section" id="ExposureControlSection">
			<h2>
				<xsl:value-of
					select="$Standard_TextTags/textTag[@key = 'ExposureControlTitle']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
			</h2>
			<table class="outlined">
				<tbody>
					<tr>
						<xsl:for-each
							select="$Standard_TextTags/textTag[@key = 'ExposureControlsTableHeader']/textTag[@key = 'FirstHeaderRow']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]/textTag">
							<td>
								<b>
									<xsl:apply-templates select="." />
								</b>
							</td>
						</xsl:for-each>
					</tr>
					<tr>
						<xsl:for-each
							select="$Standard_TextTags/textTag[@key = 'ExposureControlsTableHeader']/textTag[@key = 'SecondHeaderRow']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]/textTag">
							<td>
								<b>
									<xsl:apply-templates select="." />
								</b>
							</td>
						</xsl:for-each>
					</tr>
					<xsl:for-each select="../msds:substances/msds:substance">
						<tr>
							<td>
								<xsl:value-of
									select="$SubstanceDBs/msds:substanceDB[@key = current()/@db]/msds:substance-entry[@id=current()/@id]/msds:names/msds:name[@lang = $Language]" />
							</td>
							<td>
								<xsl:value-of
									select="$SubstanceDBs/msds:substanceDB[@key = current()/@db]/msds:substance-entry[@id=current()/@id]/msds:cas-number" />
							</td>
							<td>
								<xsl:variable name="Value1"
									select="$SubstanceDBs/msds:substanceDB[@key = current()/@db]/msds:substance-entry[@id=current()/@id]/msds:exposureLimit/msds:item[@name = 'nivågränsvärde' and @unit = 'ppm']" />
								<xsl:if test="$Value1/text()">
									<xsl:call-template name="FormatNumber">
										<xsl:with-param name="Value" select="$Value1" />
										<xsl:with-param name="FormatString"
											select="$Standard_TextTags/textTag[@key = 'FormatString_0']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
									</xsl:call-template>
								</xsl:if>
							</td>
							<td>
								<xsl:variable name="Value2"
									select="$SubstanceDBs/msds:substanceDB[@key = current()/@db]/msds:substance-entry[@id=current()/@id]/msds:exposureLimit/msds:item[@name = 'nivågränsvärde' and @unit = 'mgm3']" />
								<xsl:if test="$Value2/text()">
									<xsl:call-template name="FormatNumber">
										<xsl:with-param name="Value" select="$Value2" />
										<xsl:with-param name="FormatString"
											select="$Standard_TextTags/textTag[@key = 'FormatString_0']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
									</xsl:call-template>
								</xsl:if>
							</td>
							<td>
								<xsl:variable name="Value3"
									select="$SubstanceDBs/msds:substanceDB[@key = current()/@db]/msds:substance-entry[@id=current()/@id]/msds:exposureLimit/msds:item[@name = 'korttidsvärde' and @unit = 'ppm']" />
								<xsl:if test="$Value3/text()">
									<xsl:call-template name="FormatNumber">
										<xsl:with-param name="Value" select="$Value3" />
										<xsl:with-param name="FormatString"
											select="$Standard_TextTags/textTag[@key = 'FormatString_0']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
									</xsl:call-template>
								</xsl:if>
							</td>
							<td>
								<xsl:variable name="Value4"
									select="$SubstanceDBs/msds:substanceDB[@key = current()/@db]/msds:substance-entry[@id=current()/@id]/msds:exposureLimit/msds:item[@name = 'korttidsvärde' and @unit = 'mgm3']" />
								<xsl:if test="$Value4/text()">
									<xsl:call-template name="FormatNumber">
										<xsl:with-param name="Value" select="$Value4" />
										<xsl:with-param name="FormatString"
											select="$Standard_TextTags/textTag[@key = 'FormatString_0']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
									</xsl:call-template>
								</xsl:if>
							</td>
							<td>
								<!--
									this printout must be updated when remarks for other countries
									and languages appear in product-xml
								-->
								<xsl:value-of
									select="$SubstanceDBs/msds:substanceDB[@key = current()/@db]/msds:substance-entry[@id=current()/@id]/msds:exposureLimit/msds:item[@name = 'remark']" />
							</td>
							<td>
								<!--
									this printout must be updated when remarks for other countries
									and languages appear in product-xml
								-->
								<xsl:value-of
									select="$SubstanceDBs/msds:substanceDB[@key = current()/@db]/msds:substance-entry[@id=current()/@id]/msds:exposureLimit/msds:item[@name = 'year']" />
							</td>
						</tr>
					</xsl:for-each>
				</tbody>
			</table>
			<xsl:variable name="unique-remark"
				select="$ExposureLimitRemarks/msds:remark[msds:code = $SubstanceDBs/msds:substanceDB[@key = current()/ancestor::*/descendant::msds:substance/@db]/msds:substance-entry[@id=current()/ancestor::*/descendant::msds:substance/@id]/msds:exposureLimit/msds:item[contains(@countries, concat($Country, '; ')) and @name = 'remark']]" />
			<xsl:if test="$unique-remark">
				<p>
					<b>
						<xsl:value-of
							select="$Standard_TextTags/textTag[@key = 'ExplanationNote']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
					</b>
					<xsl:for-each select="$unique-remark">
						<xsl:sort select="msds:code" />
						<xsl:value-of select="msds:code" />
						<xsl:text>=</xsl:text>
						<xsl:value-of
							select="msds:text[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
						<xsl:if test="not(position()=last())">
							<xsl:text>, </xsl:text>
						</xsl:if>
					</xsl:for-each>
				</p>
			</xsl:if>
			<p>
				<i>
					<xsl:value-of
						select="$Standard_TextTags/textTag[@key = 'ExposureControlsExplanation']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
				</i>
			</p>
		</div>
		<p />
		<xsl:variable name="paragraphs"
			select="msds:paragraph[contains(@countries, concat($Country, '; ')) and @lang = $Language] | msds:step[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
		<xsl:if test="$paragraphs">
			<div id="section">
				<xsl:call-template name="CreateParagraphTable">
					<xsl:with-param name="Paragraphs" select="$paragraphs" />
				</xsl:call-template>
			</div>
		</xsl:if>
	</xsl:template>
	<!--  -->
	<!-- regulatoryInformation tag-->
	<!--  -->
	<xsl:template match="msds:regulatoryInformation">
		<div class="section" id="RegulatoryInformationSection">
			<h2>
				<xsl:value-of
					select="$Standard_TextTags/textTag[@key = 'RegulatoryTitle']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
			</h2>
			<xsl:if test="msds:hazardSymbols/msds:hazardSymbol">
				<xsl:apply-templates select="msds:hazardSymbols" />
			</xsl:if>
			<xsl:if test="msds:riskPhrases/msds:riskPhrase">
				<xsl:call-template name="CreateItemList">
					<xsl:with-param name="Items"
						select="$RiskPhrases/msds:riskPhrase[@key=current()/msds:riskPhrases/msds:riskPhrase/@key]" />
					<xsl:with-param name="Caption"
						select="$Standard_TextTags/textTag[@key = 'RiskPhrases']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
				</xsl:call-template>
			</xsl:if>
			<xsl:if test="msds:safetyPhrases/msds:safetyPhrase">
				<xsl:call-template name="CreateItemList">
					<xsl:with-param name="Items"
						select="$SafetyPhrases/msds:safetyPhrase[@key=current()/msds:safetyPhrases/msds:safetyPhrase/@key]" />
					<xsl:with-param name="Caption"
						select="$Standard_TextTags/textTag[@key = 'SafetyPhrases']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
				</xsl:call-template>
			</xsl:if>
			<xsl:variable name="paragraphs"
				select="msds:paragraph[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
			<xsl:if test="$paragraphs">
				<p />
				<h4>
					<xsl:value-of
						select="$Standard_TextTags/textTag[@key = 'OtherInformation']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
					<xsl:text>: </xsl:text>
				</h4>
				<xsl:call-template name="CreateParagraphTable">
					<xsl:with-param name="Paragraphs" select="$paragraphs" />
				</xsl:call-template>
			</xsl:if>
		</div>
	</xsl:template>
	<!--  -->
	<!-- OtherInformation tag-->
	<!--  -->
	<xsl:template match="msds:otherInformation">
		<div class="section" id="OtherInformationSection">
			<h2>
				<xsl:value-of
					select="$Standard_TextTags/textTag[@key = 'OtherInformationTitle']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
			</h2>
			<xsl:variable name="risks"
				select="$RiskPhrases/msds:riskPhrase[$SubstanceDBs/msds:substanceDB[@key = current()/ancestor::*/descendant::msds:substance/@db]/msds:substance-entry[@id=current()/ancestor::*/descendant::msds:substance/@id]/msds:riskPhrases/msds:riskPhrase/@key = @key]" />
			<xsl:if test="$risks">
				<xsl:call-template name="CreateItemList">
					<xsl:with-param name="Items" select="$risks" />
					<xsl:with-param name="Caption"
						select="$Standard_TextTags/textTag[@key = 'RiskPhrasesFromParagraph3']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
				</xsl:call-template>
			</xsl:if>
			<xsl:variable name="paragraphs"
				select="msds:paragraph[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
			<xsl:if test="$paragraphs">
				<p />
				<p>
					<bold>
						<xsl:value-of
							select="$Standard_TextTags/textTag[@key = 'OtherInformation']/textTag[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
						<xsl:text>: </xsl:text>
					</bold>
				</p>
				<xsl:call-template name="CreateParagraphTable">
					<xsl:with-param name="Paragraphs" select="$paragraphs" />
				</xsl:call-template>
			</xsl:if>
		</div>
	</xsl:template>
	<!--  -->
	<!-- create hazardSymbols table-->
	<!--  -->
	<xsl:template match="msds:hazardSymbols">
		<table id="symbols">
			<tbody>
				<tr>
					<xsl:for-each
						select="//msds:regulatoryInformation/msds:hazardSymbols/msds:hazardSymbol/@key">
						<td>
							<img
								src="../../ResourceFiles/Images/{$Hazards/msds:hazard[@key=current()]/msds:symbol}" />
						</td>
					</xsl:for-each>
				</tr>
				<tr>
					<xsl:for-each
						select="//msds:regulatoryInformation/msds:hazardSymbols/msds:hazardSymbol/@key">
						<td>
							<xsl:value-of
								select="$Hazards/msds:hazard[@key=current()]/msds:text[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
						</td>
					</xsl:for-each>
				</tr>
			</tbody>
		</table>
	</xsl:template>
	<!--  -->
	<!-- CreateItemList template-->
	<!--  -->
	<xsl:template name="CreateItemList">
		<xsl:param name="Items" />
		<xsl:param name="Caption" />
		<p />
		<h4>
			<xsl:value-of select="$Caption" />
			<xsl:text>: </xsl:text>
		</h4>
		<xsl:for-each select="$Items">
			<xsl:sort select="msds:code" />
			<p>
				<xsl:value-of select="msds:code" />
				<xsl:text>  </xsl:text>
				<xsl:value-of
					select="msds:text[contains(@countries, concat($Country, '; ')) and @lang = $Language]" />
			</p>
		</xsl:for-each>
	</xsl:template>
	<!--  -->
	<!--
		tags with paragraphs or steps, create section headers and table
		beneath
	-->
	<!--  -->
	<xsl:template name="CreateParagraphTable">
		<xsl:param name="Paragraphs" />
		<table>
			<tbody>
				<xsl:for-each select="$Paragraphs">
					<xsl:sort select="@pos" />
					<tr>
						<td>
							<b>
								<xsl:apply-templates select="msds:title" />
							</b>
						</td>
						<td>
							<xsl:apply-templates select="msds:text" />
						</td>
					</tr>
				</xsl:for-each>
			</tbody>
		</table>
	</xsl:template>
	<!--  -->
	<!-- Remove white-space template-->
	<!--  -->
	<xsl:template match="text()">
		<xsl:value-of select="normalize-space(.)" />
	</xsl:template>
	<!--  -->
	<!-- FormatNumber template-->
	<!--  -->
	<xsl:template name="FormatNumber">
		<xsl:param name="Value" />
		<xsl:param name="FormatString" />
		<xsl:value-of select="format-number($Value, $FormatString, $DecimalFormat)" />
	</xsl:template>
	<!--  -->
	<!--
		NO BLOCKING TEMPLATE!! replace safsf with * to switch blocking on
	-->
	<!--  -->
	<xsl:template match="safsf" />
	<!--  -->
	<!-- xhtml text formatting, more to be added?-->
	<!--  -->
	<xsl:template match="xhtml:*" xmlns:xhtml="http://www.w3.org/1999/xhtml">
		<xsl:element name="{local-name()}">
			<xsl:apply-templates />
		</xsl:element>
	</xsl:template>
</xsl:stylesheet>
